// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// This file is part of CodingEditor.
// Note:	This project is derived from Peter Project
//			(hosted on sourceforge and codeplex)
//
// Copyright (c) 2008-2009, CE Team
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


namespace CE.Main
{
	using System;
    using System.Windows.Forms;

	public sealed class ColumnEditor : Form
	{
		#region Fields

		private SourceEditor activeTextEditor;
		private Button btnCancel;
		private Button btnInsert;
		private GroupBox groupBox1;
		private GroupBox groupBox2;
		private Label label1;
		private Label label2;
		private Label label3;
		private RadioButton radioButton1;
		private RadioButton radioButton2;
		private TextBox txtIncrement;
		private TextBox txtNum;
		private TextBox txtText;

		#endregion Fields

		#region Constructors

		public ColumnEditor(SourceEditor txtEditor)
		{
			InitializeComponent();
			activeTextEditor = txtEditor;
		}

		#endregion Constructors

		#region Methods

		private void ColumnEditor_FormClosed(object sender, FormClosedEventArgs e)
		{
			if (!IsDisposed) Dispose();
		}

		private void InitializeComponent()
		{
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.label3 = new System.Windows.Forms.Label();
			this.txtText = new System.Windows.Forms.TextBox();
			this.txtNum = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.label2 = new System.Windows.Forms.Label();
			this.txtIncrement = new System.Windows.Forms.TextBox();
			this.btnInsert = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.radioButton1 = new System.Windows.Forms.RadioButton();
			this.radioButton2 = new System.Windows.Forms.RadioButton();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.SuspendLayout();
			//
			// groupBox1
			//
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.txtText);
			this.groupBox1.Location = new System.Drawing.Point(24, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(222, 56);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Text";
			//
			// label3
			//
			this.label3.AutoSize = true;
			this.label3.Location = new System.Drawing.Point(21, 22);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(34, 13);
			this.label3.TabIndex = 1;
			this.label3.Text = "Text :";
			//
			// txtText
			//
			this.txtText.Location = new System.Drawing.Point(55, 19);
			this.txtText.Name = "txtText";
			this.txtText.Size = new System.Drawing.Size(155, 20);
			this.txtText.TabIndex = 0;
			this.txtText.TextChanged += new System.EventHandler(this.TextBox_TextChanged);
			//
			// txtNum
			//
			this.txtNum.Location = new System.Drawing.Point(87, 19);
			this.txtNum.Name = "txtNum";
			this.txtNum.Size = new System.Drawing.Size(123, 20);
			this.txtNum.TabIndex = 0;
			//
			// label1
			//
			this.label1.AutoSize = true;
			this.label1.Location = new System.Drawing.Point(30, 22);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(50, 13);
			this.label1.TabIndex = 1;
			this.label1.Text = "Number :";
			//
			// groupBox2
			//
			this.groupBox2.Controls.Add(this.label2);
			this.groupBox2.Controls.Add(this.label1);
			this.groupBox2.Controls.Add(this.txtIncrement);
			this.groupBox2.Controls.Add(this.txtNum);
			this.groupBox2.Enabled = false;
			this.groupBox2.Location = new System.Drawing.Point(24, 70);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(222, 84);
			this.groupBox2.TabIndex = 1;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "Number";
			//
			// label2
			//
			this.label2.AutoSize = true;
			this.label2.Location = new System.Drawing.Point(6, 48);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(74, 13);
			this.label2.TabIndex = 1;
			this.label2.Text = "Increment by :";
			//
			// txtIncrement
			//
			this.txtIncrement.Location = new System.Drawing.Point(87, 45);
			this.txtIncrement.Name = "txtIncrement";
			this.txtIncrement.Size = new System.Drawing.Size(123, 20);
			this.txtIncrement.TabIndex = 0;
			//
			// btnInsert
			//
			this.btnInsert.Enabled = false;
			this.btnInsert.Location = new System.Drawing.Point(24, 160);
			this.btnInsert.Name = "btnInsert";
			this.btnInsert.Size = new System.Drawing.Size(104, 23);
			this.btnInsert.TabIndex = 2;
			this.btnInsert.Text = "Insert";
			this.btnInsert.UseVisualStyleBackColor = true;
			this.btnInsert.Click += new System.EventHandler(this.btnInsert_Click);
			//
			// btnCancel
			//
			this.btnCancel.Location = new System.Drawing.Point(142, 160);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.Size = new System.Drawing.Size(104, 23);
			this.btnCancel.TabIndex = 2;
			this.btnCancel.Text = "Cancel";
			this.btnCancel.UseVisualStyleBackColor = true;
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			//
			// radioButton1
			//
			this.radioButton1.AutoSize = true;
			this.radioButton1.Checked = true;
			this.radioButton1.Location = new System.Drawing.Point(4, 8);
			this.radioButton1.Name = "radioButton1";
			this.radioButton1.Size = new System.Drawing.Size(14, 13);
			this.radioButton1.TabIndex = 3;
			this.radioButton1.TabStop = true;
			this.radioButton1.UseVisualStyleBackColor = true;
			this.radioButton1.CheckedChanged += new System.EventHandler(this.RadioButton_CheckedChanged);
			//
			// radioButton2
			//
			this.radioButton2.AutoSize = true;
			this.radioButton2.Location = new System.Drawing.Point(4, 70);
			this.radioButton2.Name = "radioButton2";
			this.radioButton2.Size = new System.Drawing.Size(14, 13);
			this.radioButton2.TabIndex = 3;
			this.radioButton2.TabStop = true;
			this.radioButton2.UseVisualStyleBackColor = true;
			this.radioButton2.CheckedChanged += new System.EventHandler(this.RadioButton_CheckedChanged);
			//
			// ColumnEditor
			//
			this.ClientSize = new System.Drawing.Size(258, 195);
			this.Controls.Add(this.radioButton2);
			this.Controls.Add(this.radioButton1);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.btnInsert);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "ColumnEditor";
			this.ShowIcon = false;
			this.ShowInTaskbar = false;
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "Insert...";
			this.TopMost = true;
			this.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.ColumnEditor_FormClosed);
			this.groupBox1.ResumeLayout(false);
			this.groupBox1.PerformLayout();
			this.groupBox2.ResumeLayout(false);
			this.groupBox2.PerformLayout();
			this.ResumeLayout(false);
			this.PerformLayout();
		}

		private void RadioButton_CheckedChanged(object sender, EventArgs e)
		{
			groupBox1.Enabled = radioButton1.Checked;
			groupBox2.Enabled = !radioButton1.Checked;
		}

		private void TextBox_TextChanged(object sender, EventArgs e)
		{
			if (radioButton1.Checked && txtText.Text != string.Empty) {
				btnInsert.Enabled = true;
			}
		}

		private void btnCancel_Click(object sender, EventArgs e)
		{
			Close();
		}

		private void btnInsert_Click(object sender, EventArgs e)
		{
			activeTextEditor.ColumnAdd(txtText.Text);
		}

		#endregion Methods
	}
}